<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>手动提交报告</title>
</head>
<body>
<section>
    <div>
        <div class="layui-card">
            <div class="adp-content">
                <form id="queryForm"></form>
                <button ADP_BTN id="batchReport" method="batchReport">
                    <i class="layui-icon layui-icon-add-circle-fine"></i>
                    批量上报
                </button>
                <table id="queryTable"></table>
            </div>
        </div>
    </div>
</section>
</body>
</html>

<script src="../static/adp/import.js"></script>

<script type="text/html" id="OPERATION_ROW_TPL">
    <a class="layui-btn layui-btn-sm" lay-event="report">
        <i class="layui-icon layui-icon-edit"></i>
        上报
    </a>

    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">
        <i class="layui-icon layui-icon-delete"></i>
        删除
    </a>
</script>

<script type="text/javascript">

    var queryform = $("#queryForm").adpForm({
        elem: [
            {type: "text", label: "工位", name: "staCode", placeholder: "请输入工位"},
            {type: "text", label: "EPC编码", name: "epcCode", placeholder: "请输入EPC"},
            {type: "text", label: "进出标识", name: "flag", placeholder: "请输入进出标识"},
            {
                type: "select", label: "上报状态", name: "reportStatus", placeholder: "请选择上报状态",
                data: [{key: "", value: "全部"},
                    {key: "成功", value: "成功"},
                    {key: "失败", value: "失败"},
                    {key: "未上报", value: "未上报"}]
            },
            {type: "date", label: "时间", name: "datetime", placeholder: "请选择时间"}],
        button: [{type: "submit", label: "查询", method: "query", icon: 'query'},
            {type: "reset", label: "重置"}],
        methods: {
            query: function query(data) {
                queryTable.reload(data);
            }
        }
    });

    var queryTable = $("#queryTable").adpTable({
        url: '../rs/ManualReport/list',
        enableCheckbox: true,
        pageSize: 10,
        where: queryform.data(),
        cols: [[
            {field: 'id', title: 'ID', type: 'checkbox', width: 30, sort: true, fixed: 'left'},
            {field: 'staCode', title: '工位', width: 160},
            {field: 'epcCode', title: 'EPC编码', width: 240},
            {field: 'datetime', title: '记录时间', width: 160},
            {field: 'flag', title: '进出标识', width: 100},
            {field: 'reportStatus', title: '上报状态', width: 120},
            {fixed: 'right', title: '操作', width: 180, align: 'center', toolbar: '#OPERATION_ROW_TPL'}
        ]],
        methods: {
            report: function report(data, tr) {
                layer.confirm('是否重新上传？', function (index) {
                    SV("ManualReport")("singleReport")({ids: [data.id]});
                    queryTable.reload();
                    layer.close(index);
                });
            },
            del: function del(data, tr) {
                layer.confirm('真的删除行么', function (index) {
                    SV("ManualReport")("delete")({ids: [data.id]});
                    queryTable.reload(queryform.data());
                    layer.close(index);
                });
            }
        }
    });

    function batchReport() {

        var _queryTable$checkStat = queryTable.checkStatus(),
            data = _queryTable$checkStat.data;
        var ids = new Array();
        $.each(data, function (n, value) {
            ids.push(value.id);
        });
        layer.confirm('是否批量上报', function (index) {
            SV("ManualReport")("singleReport")({
                "ids": ids
            })
            queryTable.reload();
            layer.close(index);
        });
    }

</script>